$(function () {
    getServiceTypeFindAll();
    let id = localStorage.getItem("orderId");
    findById(id);
});

function getServiceTypeFindAll() {
    let result = myAjax('/back/serviceType/findType','get',{token:$.cookie("token")});
    data = result.list;
    let html = "";
    for (let i = 0; i < data.length; i++) {
        html += '<option value="' + data[i].id + '">' + data[i].serviceType + '</option>';
    }
    $("#roomType").html(html);//将页面格式加载到页面布局
}

function findById(id) {
    let result = myAjax('/back/order/findById','get',{id:id});
    showOrder(result.orderModel);
}

function showOrder(data) {
    $("#orderId").val(data.id);
    $("#username").val(data.username);
    $("input[name='sex'][value='" + data.sex + "']").attr("checked", true);
    $("#phone").val(data.phone);
    // $("#roomType option[text='服务式客房及套房']").attr("selected", true);
    $('#roomType option').filter(function(){return $(this).text()==data.roomType;}).attr("selected",true);
    $("input[name='channel'][value='" + data.channel + "']").attr("checked", true);
    $("#reservationTime").val(data.reservationTime);
    $("#checkInTime").val(data.checkInTime);
    $("#checkOutTime").val(data.checkOutTime);
}

function orderEdit() {
    let data = {};
    data.id=$("#orderId").val();
    data.username = $("#username").val();
    data.sex = $("input[name='sex']:checked").val();
    data.phone = $("#phone").val();
    data.roomType = $("#roomType option:selected").text();
    data.channel = $("input[name='channel']:checked").val();
    data.reservationTime = $("#reservationTime").val();
    data.checkInTime = $("#checkInTime").val();
    data.checkOutTime = $("#checkOutTime").val();
    data.token=$.cookie("token");
    let result = myAjax('/back/order/orderEdit','get',data);
    if (result.result === 1) {
        alert("修改成功!")
        $("#right").load('/back/order/orderManage.html');
    }else {
        alert("修改失败！")
    }
}

function cancelOreder() {
    $("#right").load('/back/order/orderManage.html');
}